import Vue from 'vue'
import Router from 'vue-router'
import index from '@/view/index'
import login from '@/view/login'
import messagelogin from '@/view/messagelogin'
import home from '@/view/home'
import goods from '@/view/goods'
import shopcar from '@/view/shopcar'
import personal from '@/view/personal'
import conforder from '@/view/conforder'
import homePage from '@/view/personal/homePage'
import information from '@/view/personal/information'
import address from '@/view/personal/address'
import ordercenter from '@/view/personal/ordercenter'
import adminlogin from '@/view/adminlogin'
import category from '@/view/category'
import adminindex from '@/view/manager/adminindex'
import userManager from '@/view/manager/userManager'
import orderManager from '@/view/manager/orderManager'
import shoesManager from '@/view/manager/shoesManager'
import addressManager from '@/view/manager/addressManager'
import VDistpicker from 'v-distpicker'

Vue.component('v-distpicker', VDistpicker)

Vue.use(Router)
// 给路由跳转添加异常类回调函数，如果缺失那么js会报错
const routerPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}

export default new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login
    },
    {
      path: '/messagelogin',
      name: 'messagelogin',
      component: messagelogin
    },
    {
      path: '/home',
      name: 'home',
      component: home
    },
    {
      path: '/goods',
      name: 'goods',
      component: goods
    },
    {
      path: '/shopcar',
      name: 'shopcar',
      component: shopcar
    },
    {
      path: '/personal',
      name: 'personal',
      component: personal,
      redirect: {name: 'homePage'},
      children: [
        {
          path: '/homePage',
          name: 'homePage',
          component: homePage
        },
        {
          path: '/information',
          name: 'information',
          component: information
        },
        {
          path: '/address',
          name: 'address',
          component: address
        },
        {
          path: '/ordercenter',
          name: 'ordercenter',
          component: ordercenter
        }
      ]
    },
    {
      path: '/adminlogin',
      name: 'adminlogin',
      component: adminlogin
    },
    {
      path: '/adminindex',
      name: 'adminindex',
      component: adminindex,
      redirect: {name: 'userManager'},
      children: [
        {
          path: '/userManager',
          name: 'userManager',
          component: userManager
        },
        {
          path: '/orderManager',
          name: 'orderManager',
          component: orderManager
        },
        {
          path: '/shoesManager',
          name: 'shoesManager',
          component: shoesManager
        },
        {
          path: '/addressManager',
          name: 'addressManager',
          component: addressManager
        }
      ]
    },
    {
      path: '/conforder',
      name: 'conforder',
      component: conforder
    },
    {
      path: '/category',
      name: 'category',
      component: category
    },
    {
      path: '/index',
      name: 'index',
      component: index
    }
  ]
})
